package com.tungse.study.mini_spring.web;

import com.tungse.study.mini_spring.annotation.MyComponent;
import com.tungse.study.mini_spring.annotation.MyInterceptor;
import com.tungse.study.mini_spring.interceptor.MyHandlerInterceptorAdapter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.util.Arrays;

/**
 * @Author : Tungse
 * @Date: 2025/4/13 10:32
 * @Description:
 */
@MyComponent
@MyInterceptor
public class TestInterceptor implements MyHandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  {
        System.out.println("preHandle");
        return true;
    }

    /**
     * This implementation is empty.
     */
    @Override
    public void postHandle(
            HttpServletRequest request, HttpServletResponse response, Object handler, Object modelAndView) {
        System.out.println("postHandle");
    }

    /**
     * This implementation is empty.
     */
    @Override
    public  void afterCompletion(
            HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        System.out.println("afterCompletion");
        if(ex != null) {
            System.out.println(Arrays.toString(ex.getStackTrace()));
        }
    }
}
